package com.hqd.ch03.v26.aop.config;

import com.hqd.ch03.v26.aop.framework.AopInfrastructureBean;
import com.hqd.ch03.v26.aware.BeanFactoryAware;
import com.hqd.ch03.v26.factory.BeanFactory;
import com.hqd.ch03.v26.factory.FactoryBean;
import com.hqd.ch03.v26.utils.BeanUtils;

import java.lang.reflect.Method;

/**
 * 获取增强方法
 */
public class MethodLocatingFactoryBean implements FactoryBean<Method>, BeanFactoryAware, AopInfrastructureBean {
    private String targetBeanName;

    private String methodName;

    private Method method;

    public String getTargetBeanName() {
        return targetBeanName;
    }

    public void setTargetBeanName(String targetBeanName) {
        this.targetBeanName = targetBeanName;
    }

    public String getMethodName() {
        return methodName;
    }

    public void setMethodName(String methodName) {
        this.methodName = methodName;
    }

    @Override
    public Class<?> getObjectType() {
        return Method.class;
    }

    @Override
    public Method getObject() {
        return this.method;
    }

    @Override
    public void setBeanFactory(BeanFactory beanFactory) {
        Class<?> beanClass = beanFactory.getType(this.targetBeanName);
        this.method = BeanUtils.resolveSignature(this.methodName, beanClass);
    }
}
